package fivestar.model.dao.hibernate;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import fivestar.model.dao.InvoiceDao;
import fivestar.util.HibernateUtil;

public class InvoiceDaoHibernate implements InvoiceDao {

	Session session = null;
	Transaction tx = null;
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Object[]> findlByDni(String dni) throws RuntimeException {
		 
		List<Object[]> lista = null;
		session = HibernateUtil.getSessionFactory().openSession();
		try {
			tx = session.beginTransaction();
			Query query = session.createQuery("select i.invoiceId, i.date,i.datepayment,i.formpayment,i.paid,i.total from Invoice i where i.guest.dni=:dni");
			 query.setString("dni",dni);			 
			 lista =  query.list();
		} catch (HibernateException e) {
			e.printStackTrace();
		} finally {
			session.flush();
			session.close();
		}
		return lista;	
	
	}

}
